#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi
 
 

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_geopt_ccpt_h2o.info <<%EOF%
   cc_geopt_ccpt_h2o
   -----------------
   Molecule:         H2O, C2v 
   Wave Function:    CCSD(T) / cc-pVDZ
   Test Purpose:     CCSD(T) geometry optimization
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_geopt_ccpt_h2o.mol <<%EOF%
BASIS
cc-pVDZ
Geometry optimization calculations
for H2O
    2    2  X  Y  Z   1.00D-15
        1.0   1
H     0.0000000000000000  1.427450200000000   0.986437000000000       *
        8.0   1
O     0.0000000000000000  0.000000000000000   -0.1243090000000        *
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_geopt_ccpt_h2o.dal <<%EOF%
**DALTON INPUT
.OPTIMIZE
**INTEGRAL
.DIPLEN
.DEROVL
.DERHAM
**WAVE FUNCTION
.TITLE
   test case for CCSD(T) geometry optimization
.CC
*SCF INPUT
.THRESH
 1.0D-10
*CC INPUT
.CC(T)
.THRENR
 1.0d-08
.THRLEQ
 1.0d-08
.PRINT
 2
.NSYM
 4
.FROIMP
1 0 0 0
0 0 0 0
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_geopt_ccpt_h2o.check
cat >>cc_geopt_ccpt_h2o.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

#SCF, MP2, CCSD and CCSD(T) energies of 0 iteration:
CRIT1=`$GREP "Final * HF energy: * -76\.026804804" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -76\.228449905" $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * -76\.238013267" $log | wc -l`
CRIT4=`$GREP "Total energy CCSD\(T\): * -76\.241049324" $log | wc -l`
CRIT5=`$GREP " H *_1 * ( |0)\.0000000000 *  1\.42795954.. * ( |0)\.99250035.." $log | wc -l`
CRIT6=`$GREP " H *_2 * ( |0)\.0000000000 * -1\.42795954.. * ( |0)\.99250035.." $log | wc -l`
CRIT7=`$GREP " O * ( |0)\.0000000000 * ( |0)\.0000000000 * ( \-|\-0)\.13643570.." $log | wc -l` 
CRIT8=`$GREP "Energy at this geometry is * : * -76\.241049" $log | wc -l`
CRIT9=`$GREP "Norm of gradient * : * ( |0)\.019470" $log | wc -l`
CRIT0=`$GREP "Norm of step * : * ( |0)\.02258." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT0`
CTRL[1]=16
ERROR[1]="INITIAL ITERATION IS ALREADY NOT CORRECT"


#SCF, MP2, CCSD and CCSD(T) energies of 1 iteration:
CRIT1=`$GREP "Final * HF energy: * -76\.026438212(3|4).." $log | wc -l`
CRIT2=`$GREP "Total RSTAR energy: * -76\.237664273." $log | wc -l`
CRIT3=`$GREP "Total CCSD  energy: * -76\.23816985(7|8)." $log | wc -l`
CRIT4=`$GREP "Total energy CCSD\(T\): * -76\.241243811." $log | wc -l`
CRIT5=`$GREP " H *_1 * ( |0)\.0000000000 *  1\.42223922.. * ( |0)\.99842254.." $log | wc -l`
CRIT6=`$GREP " H *_2 * ( |0)\.0000000000 * -1\.42223922.. * ( |0)\.99842254.." $log | wc -l`
CRIT7=`$GREP " O * ( |0)\.0000000000 * ( |0)\.0000000000 * ( \-|\-0)\.14828009.." $log | wc -l`
CRIT8=`$GREP "Energy at this geometry is * : * -76\.24124[34]" $log | wc -l`
CRIT9=`$GREP "Norm of gradient * : * ( |0)\.00751." $log | wc -l`
CRIT0=`$GREP "Norm of step * : * ( |0)\.02419." $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5 \+ $CRIT6 \+ $CRIT7 \+ $CRIT8 \+ $CRIT9 \+ $CRIT0`
CTRL[2]=16
ERROR[2]="FIRST ITERATION IS ALREADY NOT CORRECT"
#
# Final summary:
CRIT1=`$GREP " H *_1 * ( |0)\.0000000000 *  1\.41821331.. * ( |0)\.9996215..." $log | wc -l`
CRIT2=`$GREP " H *_2 * ( |0)\.0000000000 * -1\.41821331.. * ( |0)\.9996215..." $log | wc -l`
CRIT3=`$GREP " O * ( |0)\.0000000000 * ( |0)\.0000000000 * ( \-|\-0)\.1506780..." $log | wc -l`
CRIT4=`$GREP "Geometry converged in * 5 *iterations" $log | wc -l`
CRIT5=`$GREP "Energy at final geometry is * : * -76\.241305 " $log | wc -l`
TEST[3]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 \+ $CRIT4 \+ $CRIT5`
CTRL[3]=14
ERROR[3]="FINAL SUMMARY IS NOT CORRECT"
#
PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi
%EOF%
chmod +x cc_geopt_ccpt_h2o.check
#######################################################################
